package com.by.course.controller.user;


import com.by.course.config.web.jwt.PassToken;
import com.by.course.entity.base.BaseResult;
import com.by.course.entity.base.PageResult;
import com.by.course.entity.vo.course.resp.BaseCourseResultVO;
import com.by.course.entity.vo.login.req.LoginVO;
import com.by.course.entity.vo.login.resp.LoginResultVO;
import com.by.course.entity.vo.user.req.AddBaseUserVO;
import com.by.course.entity.vo.user.req.DeleteBaseUserVO;
import com.by.course.entity.vo.user.req.GetBaseUserVO;
import com.by.course.entity.vo.user.req.UpdateBaseUserVO;
import com.by.course.entity.vo.user.resp.BaseUserResultVO;
import com.by.course.serivce.BaseUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user")
@Api(tags = "用户接口")
public class UserController {

    @Resource
    private BaseUserService baseUserService;

    @PassToken
    @ApiOperation("登录")
    @PostMapping("/login")
    public BaseResult<LoginResultVO> login(@RequestBody LoginVO vo) {
        return baseUserService.login(vo);
    }

    @ApiOperation("用户管理--添加用户")
    @PostMapping("/createUser")
    public BaseResult<String> createUser(@RequestBody AddBaseUserVO vo) {
        return baseUserService.createUser(vo);
    }

    @ApiOperation("用户管理--修改用户")
    @PostMapping("/updateUser")
    public BaseResult<String> updateUser(@RequestBody UpdateBaseUserVO vo) {
        return baseUserService.updateUser(vo);
    }

    @ApiOperation("用户管理--删除用户")
    @PostMapping("/deleteUser")
    public BaseResult<String> deleteUser(@RequestBody DeleteBaseUserVO vo) {
        return baseUserService.deleteUser(vo);
    }

    @ApiOperation("用户管理--查询某个用户")
    @PostMapping("/getUserById")
    public BaseResult<BaseUserResultVO> getUserById(@RequestBody GetBaseUserVO vo) {
        return baseUserService.getUserById(vo);
    }

    @ApiOperation("用户管理--查询某个用户的课程列表")
    @PostMapping("/getUserCourseList")
    public BaseResult<List<BaseCourseResultVO>> getUserCourseListById(@RequestBody GetBaseUserVO vo) {
        return baseUserService.getUserCourseList(vo);
    }

    @ApiOperation("用户管理--分页查询用户")
    @PostMapping("/queryUsers")
    public BaseResult<PageResult<BaseUserResultVO>> queryUsers(@RequestBody GetBaseUserVO vo) {
        return baseUserService.queryUsers(vo);
    }
}
